package de.herberlin.pss.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

public class Popup extends JDialog implements HyperlinkListener {
	private static final long serialVersionUID = 1L;

	public Popup(JFrame parent, String filename) {
		super(parent);
		this.setTitle("PSS-Client");
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		JEditorPane txt = new JEditorPane();
		txt.setEditable(false);
		txt.setContentType("text/html");
		txt.enableInputMethods(true);
		txt.addHyperlinkListener(this);
		try {
			txt.setPage(getClass().getResource(filename));
		} catch (Exception e) {
			Frame.showMessage("Error reading: " + filename, e);
		}
		this.setLayout(new BorderLayout());
		this.add(new JScrollPane(txt), BorderLayout.CENTER);
		this.setSize(new Dimension(320, 240));
		this.setVisible(true);
	}

	public void hyperlinkUpdate(HyperlinkEvent e) {
		if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
			try {
					((JEditorPane) e.getSource()).setPage(e.getURL());
			} catch (Exception ex) {
				Frame.showMessage("Error reading: " + e.getURL(), ex);
				ex.printStackTrace();
			}
		}

	}
}
